package com.mail.server.controller;


import com.mail.model.db.SmsHomeNewProduct;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.SmsHomeNewProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 新鲜好物表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    private SmsHomeNewProductService smsHomeNewProductService;

    @PostMapping("/create")
    public R<String> addNewProduct(@RequestBody List<SmsHomeNewProduct> newProducts){
        smsHomeNewProductService.addNewProduct(newProducts);
        return R.success("");
    }

    @PostMapping("/delete")
    public R<String> deleteNewProduc(@RequestParam("ids") List<Long> ids) {
        smsHomeNewProductService.deleteBrand(ids);
        return R.success("");
    }

    @GetMapping("/list")
    public R<PageResult> getNewProducByPage(@RequestParam(defaultValue = "1") Long pageNum,
                                    @RequestParam(defaultValue = "10") Long pageSize,
                                    String productName,
                                    Integer recommendStatus){
        PageResult page = smsHomeNewProductService.getNewProducByPage(pageNum,pageSize,productName,recommendStatus);
        return R.success(page);
    }

    @PostMapping("/update/recommendStatus")
    public R<String> updateNewProduct(@RequestParam("ids") List<Long> ids,@RequestParam("recommendStatus") Integer recommendStatus){
        smsHomeNewProductService.updateNewProduct(ids,recommendStatus);
        return R.success("");
    }

    @PostMapping("/update/sort/{id}")
    public R<String> updatesortNewProduct(@PathVariable("id") Long id,@RequestParam(required = false) Integer sort){
        smsHomeNewProductService.updatesortNewProduct(id,sort);
        return R.success("");
    }
}
